package com.mediacloud.app.newsmodule.fragment.video.vod

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.mediacloud.app.newsmodule.R

class MemberHeaderAdapter(context:Context?) : RecyclerView.Adapter<MemberHeaderAdapter.HeaderHolder>() {

    var mData : MutableList<Int> = mutableListOf(
        R.drawable.default_head,
        R.drawable.default_head,
        R.drawable.default_head,
        R.drawable.default_head,
        R.drawable.default_head,
        R.drawable.default_head,
        R.drawable.default_head,
        R.drawable.default_head,
        R.drawable.aduio_thumb,
        R.drawable.appfactory_top_more_img
    )
    var mContext = context

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int):HeaderHolder {
        return HeaderHolder(LayoutInflater.from(mContext).inflate(R.layout.item_header,parent,false))
    }

    override fun onBindViewHolder(holder: HeaderHolder, position: Int) {
        holder.ivHeader.setImageResource(mData[position])
        if (position == 0){
            setMargin(holder.ivHeader,0,0,0,0)
        }else{
            setMargin(holder.ivHeader,-15,0,0,0)
        }
    }

    fun setMargin(v:View,l:Int,t:Int,r:Int,b:Int){
        if (v.layoutParams is ViewGroup.MarginLayoutParams){
            val marginLayoutParams = v.layoutParams as ViewGroup.MarginLayoutParams
            marginLayoutParams.setMargins(l,t,r,b)
            v.requestLayout()
        }
    }
    override fun getItemCount(): Int {
        return mData.size
    }

    class HeaderHolder(view: View):RecyclerView.ViewHolder(view){
       val ivHeader:ImageView =  view.findViewById(R.id.ivHeader)
    }
}